//
//  GFGlViewController.m
//  Qyer
//
//  Created by dlios on 15/10/22.
//  Copyright (c) 2015年 GF. All rights reserved.
//

#import "GFGlViewController.h"

@interface GFGlViewController ()


@end

@implementation GFGlViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    _table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [_table setDelegate:self];
    [_table setDataSource:self];
    [_table setBounces:YES];
//    [self setDelegate:self];
    [self.view addSubview:_table];
    [self getGlString:self.glString];
}

- (void)getGlString: (NSString *)string{
    _tableArr = [NSMutableArray array];
    [AFN getdataWithString:string block:^(id block) {
        for (NSDictionary *dic in block) {
            GFJnModel *model = [GFJnModel modelWithDictionary:dic];
            [_tableArr addObject:model];
        }
        [_table reloadData];
    } BLOCK:^(id BLOCK) {
        
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _tableArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 220 * HEIGHT;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *guoFeng = @"cell";
    GFGlTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:guoFeng];
    if (!cell) {
        cell = [[GFGlTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:guoFeng];
    }
    GFJnModel *model = [_tableArr objectAtIndex:indexPath.row];
    [cell getJnModel:model];
    [cell.lcButton addTarget:self action:@selector(lcButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [cell.lcButton setTag:indexPath.row + 1000];
    
    [cell.lxdButton addTarget:self action:@selector(lxdButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [cell.lxdButton setTag:indexPath.row + 1000];
    
    [cell.ztButton addTarget:self action:@selector(ztButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [cell.ztButton setTag:indexPath.row + 1000];
    return cell;
}

- (void)lcButtonClick: (UIButton *)sender{
    NSString *preString = @"http://chanyouji.com/api/destinations/plans/";
    NSString *hasString = @".json?page=";
    GFJnModel *model = [_tableArr objectAtIndex:sender.tag - 1000];
    NSString *comString = [NSString stringWithFormat:@"%@%@%@", preString, model.cId, hasString];
    GFLcViewController *lc = [[GFLcViewController alloc] init];
    lc.afnString = comString;
    [self.navigationController pushViewController:lc animated:YES];
}


- (void)lxdButtonClick: (UIButton *)sender{
    NSString *preString = @"http://chanyouji.com/api/destinations/attractions/";
    NSString *hasString = @".json?page=";
    GFJnModel *model = [_tableArr objectAtIndex:sender.tag - 1000];
    NSString *comString = [NSString stringWithFormat:@"%@%@%@", preString, model.cId, hasString];
    GFLxdViewController *lxd = [[GFLxdViewController alloc] init];
    lxd.afnString = comString;
    [self.navigationController pushViewController:lxd animated:YES];
}

- (void)ztButtonClick: (UIButton *)sender{
    NSString *preString = @"http://chanyouji.com/api/articles.json?destination_id=";
    NSString *hasString = @"&page=1";
    GFJnModel *model = [_tableArr objectAtIndex:sender.tag - 1000];
    NSString *comString = [NSString stringWithFormat:@"%@%@%@", preString, model.cId, hasString];
    GFZtViewController *zt = [[GFZtViewController alloc] init];
    zt.afnString = comString;
    [self.navigationController pushViewController:zt animated:YES];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
